package com.xyy.saas.payment.cores.enums;

/**
 * @Date: 2020/2/28 15:07
 */
public enum AccountTypeEnum {

    /**
     * 对公户 开户
     */
    BUSINESS("business"),
    /**
     * 对私户 开户
     */
    CUSTOMER("customer"),

    /**
     * 对公户 绑卡
     */
    BUSINESS_BIND("business_bind"),
    /**
     * 对私户 绑卡
     */
    CUSTOMER_BIND("customer_bind"),

    /**
     * 对公户 修改基本信息
     */
    BUSINESS_MODIFY("business_modify"),
    /**
     * 对私户 修改基本信息
     */
    CUSTOMER_MODIFY("customer_modify")
    ;

    private String type;

    AccountTypeEnum(String type){
        this.type = type;
    }

    /**
     * 是否需要加入灰度
     * @param sendActiveCodeType 短信验证码类型
     * @return
     */
    public static boolean needAddUpgrade(String sendActiveCodeType) {
        return BUSINESS.getType().equals(sendActiveCodeType) ||
                CUSTOMER.getType().equals(sendActiveCodeType);
    }

    public static AccountTypeEnum getAccountTypeEnum(String accountType) {
        for(AccountTypeEnum accountTypeEnum : values()) {
            if(accountTypeEnum.getType().equals(accountType)) {
                return accountTypeEnum;
            }
        }

        return null;
    }

    /**
     * 富民1.0
     */
    public static String getOperateType(String accountType) {
        return getOperateType(getAccountTypeEnum(accountType));
    }

    /**
     * 富民2.0
     * baseAccountComplete 基本户是否已完成，进件修改基本户信息
     */
    public static String getOperateType2(String accountType, boolean baseAccountComplete) {
        return getOperateType2(getAccountTypeEnum(accountType), baseAccountComplete);
    }

    /**
     * 富民1.0
     */
    private static String getOperateType(AccountTypeEnum accountType) {
        if(accountType == null) {
            throw new RuntimeException("accountType is null.");
        }

        switch(accountType) {
            case CUSTOMER:
                return "01";
            case BUSINESS:
                return "03";
            case CUSTOMER_BIND:
                return "20";
            case BUSINESS_BIND:
                return "21";
        }

        throw new RuntimeException("accountType is null.");
    }

    /**
     * 富民2.0
     */
    private static String getOperateType2(AccountTypeEnum accountType, boolean baseAccountComplete) {
        if(accountType == null) {
            throw new RuntimeException("accountType is null.");
        }

        switch(accountType) {
            case CUSTOMER:
                return baseAccountComplete ? "PERSONAL_REAL_NAME_MODIFY" : "PERSONAL_REAL_NAME_OPEN";
            case BUSINESS:
                return baseAccountComplete ? "ENTERPRISE_REAL_NAME_MODIFY" : "ENTERPRISE_REAL_NAME_OPEN";
            case CUSTOMER_BIND:
                return "PERSONAL_BIND_CARD";
            case BUSINESS_BIND:
                return "ENTERPRISE_BIND_CARD";
            case CUSTOMER_MODIFY:
                return "PERSONAL_REAL_NAME_MODIFY";
            case BUSINESS_MODIFY:
                return "ENTERPRISE_REAL_NAME_MODIFY";
        }

        throw new RuntimeException("accountType is null.");
    }

    public String getType() {
        return type;
    }
}
